package com.gd.iot.energy.controller.datamanage;

import com.gd.iot.energy.annotation.SystemLogRecordMonitor;
import com.gd.iot.energy.entity.ResponseEntity;
import com.gd.iot.energy.pojo.common.vo.PageVO;
import com.gd.iot.energy.pojo.datamanage.dto.SysconfigTaskSaveDTO;
import com.gd.iot.energy.pojo.datamanage.vo.SysconfigTaskPageVO;
import com.gd.iot.energy.pojo.datamanage.vo.SysconfigTaskVO;
import com.gd.iot.energy.pojo.systemadmin.vo.EnumVO;
import com.gd.iot.energy.service.datamanage.SysconfigTaskService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * 数据管理-采集管理-定时任务
 *
 * @author kris
 * @date Created at 2020/8/3 10:50
 */
@RestController
@RequestMapping("/admin/task")
@Api(value = "数据管理-采集管理-定时任务",tags = "数据管理-采集管理-定时任务")
public class SysconfigTaskController {
    @Autowired
    private SysconfigTaskService sysconfigTaskService;

    @ApiOperation("获取定时任务分页列表")
    @SystemLogRecordMonitor("获取定时任务分页列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "equipId", value = "区域编号", dataType = "string", paramType = "query", example = "", required = true),
            @ApiImplicitParam(name = "filterType", value = "过滤类型", dataType = "string", paramType = "query", example = "", required = false),
            @ApiImplicitParam(name = "filterValue", value = "过滤条件", dataType = "string", paramType = "query", example = "", required = false),
            @ApiImplicitParam(name = "pageSize", value = "每页数量", dataType = "string", paramType = "query", example = "", required = false),
            @ApiImplicitParam(name = "pageNum", value = "页码", dataType = "string", paramType = "query", example = "", required = false),
            @ApiImplicitParam(name = "orderColumn", value = "排序字段", dataType = "string", paramType = "query", example = "", required = false),
            @ApiImplicitParam(name = "orderType", value = "排序类型", dataType = "string", paramType = "query", example = "", required = false),
    })
    @PostMapping("/getPageList")
    public ResponseEntity<PageVO<SysconfigTaskPageVO>> getPageList(
            @RequestParam(value = "equipId",required = true)Long equipId,
            @RequestParam(value = "filterType",required = false)Integer filterType,
            @RequestParam(value = "filterValue",required = false)String filterValue,
            @RequestParam(value = "pageSize",required = false,defaultValue = "10")Integer pageSize,
            @RequestParam(value = "pageNum",required = false,defaultValue = "1")Integer pageNum,
            @RequestParam(value = "orderColumn",required = false,defaultValue = "id") String orderColumn,
            @RequestParam(value = "orderType",required = false,defaultValue = "asc") String orderType
    ) {

        PageVO<SysconfigTaskPageVO> pageVO = sysconfigTaskService.getSysconfigTaskPageVOs(equipId,filterType,filterValue,pageSize,pageNum,orderColumn,orderType);
        return new ResponseEntity<>(pageVO);
    }

    @ApiOperation("获取定时任务列表")
    @SystemLogRecordMonitor("获取定时任务列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "equipId", value = "区域编号", dataType = "string", paramType = "query", example = "", required = true),
            @ApiImplicitParam(name = "name", value = "户名", dataType = "string", paramType = "query", example = "", required = false)
    })
    @PostMapping("/getList")
    public ResponseEntity<List<SysconfigTaskVO>> getList(@RequestParam(value = "equipId",required = true,defaultValue = "10")Long equipId,
                                                     @RequestParam(value = "name",required = false)String name) {

        List<SysconfigTaskVO> sysconfigTaskVOS = sysconfigTaskService.getSysconfigTaskVOs(equipId, name);
        return new ResponseEntity<>(sysconfigTaskVOS);
    }

    @ApiOperation("获取定时任务")
    @SystemLogRecordMonitor("获取定时任务")
    @PostMapping("/get")
    public ResponseEntity<SysconfigTaskSaveDTO> get(Integer id){
        SysconfigTaskSaveDTO taskSaveDTO = sysconfigTaskService.getSysconfigTask(id);
        return new ResponseEntity<>(taskSaveDTO);
    }

    @ApiOperation("新增定时任务")
    @SystemLogRecordMonitor("新增定时任务")
    @PostMapping("/add")
    public ResponseEntity<Long> add(@RequestBody SysconfigTaskSaveDTO taskSaveDTO){
        Long id = sysconfigTaskService.add(taskSaveDTO);
        return new ResponseEntity<>(id);
    }

    @ApiOperation("更新定时任务")
    @SystemLogRecordMonitor("更新定时任务")
    @PostMapping("/update")
    public ResponseEntity<Boolean> update(@RequestBody SysconfigTaskSaveDTO taskSaveDTO){
        boolean res = sysconfigTaskService.update(taskSaveDTO);
        return new ResponseEntity<>(res);
    }

    @ApiOperation("删除定时任务")
    @SystemLogRecordMonitor("删除定时任务")
    @PostMapping("/delete")
    public ResponseEntity<Boolean> delete(@RequestBody List<Integer> ids){
        boolean res = sysconfigTaskService.delete(ids);
        return new ResponseEntity<>(res);
    }

    @ApiOperation("获取相关枚举")
    @SystemLogRecordMonitor("获取相关枚举")
    @PostMapping("/getEquipmentType")
    public ResponseEntity<Map<String, List<EnumVO>>> getEquipmentType(){
        Map<String, List<EnumVO>> enums = sysconfigTaskService.getEnums();
        return new ResponseEntity<>(enums);
    }
}
